//
//  Robot.h
//  NXTRemoteController
//
//  Created by naceka on 24.03.12.
//  Copyright 2012 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Sensor.h"
#import "BTstackManager.h"

enum Motor {
	MOTOR_A = 0x00,
	MOTOR_B = 0x01,
	MOTOR_C = 0x02,
	MOTOR_ALL = 0xFF
};

//notification about new data
@protocol SensorDataDelegate
@optional
- (void) sensorDataUpdated:(int) sn;
@end

@interface Robot : NSObject <BTstackManagerDelegate>{
	
	//bluetooth
	BTstackManager * manager;
	//device address
	bd_addr_t * device_address;
	//sensors
	Sensor * sensors[4];
	//left motor number(A/B/C)
	enum Motor leftMotor;
	//right motor number(A/B/C)
	enum Motor rightMotor;
	//speed
	char speed;
	//timer for update sensor data
	NSTimer * timer;
	//delegate for sensor data
	id <SensorDataDelegate> delegate;
}

//init method
- (Robot *) init;

//set of NXT id
- (void) setNxtId:(bd_addr_t *) addr;
- (NSString *) getNxtId;

//register of sensor type method
- (void) registerSensor:(Sensor *) sensor OnPort:(int) port;
- (Sensor *) sensorAt:(int)i;

//update sensor data
- (void) updateSensorData;

//register motor method
- (void) registerLeftMotor:(enum Motor) motor;
- (void) registerRightMotor:(enum Motor) motor;

//connection methods
- (void) connect;
- (void) disconnect;

//speed method
- (void) setSpeed:(int) _sp;
	
//move methods
- (void) moveForward;
- (void) moveBackward;
- (void) moveLeft;
- (void) moveRight;
- (void) stop;
- (void) moveLeft:(char) lspeed andRight:(char) rspeed;

//BTstackManagerDelegate
- (void) btActivated;
- (void) btActivationFailed;
- (void) btDeactivated;
- (void) btDeviceConnected;
- (void) btDeviceDisconnected;
- (void) btReceivedD1:(uint8_t) d1 andD2: (uint8_t) d2 fromSensor:(int) sn;

//SensorDataDelegate
- (void) setDelegate:(id <SensorDataDelegate>) d;
@end
